package android.crosstime.hes;

import java.io.File;

public class ListItem {

	public String FullPath; // path+filename
	public String Path;		// only path
	public String Name;		// name(can be not same with filename)
	public int	IconId;		// icon resource ID
	public int ItemType = ListItemUtil.TYPE_NORMAL;  //Item type
	public int FileType; //file type integer representation
	
	public ListItem(){
		this.Path = "";
		this.Name = "";
		this.IconId = ListItemUtil.ICON_UNKNOWN;
		this.ItemType = ListItemUtil.TYPE_NORMAL;
	}
	
	public ListItem(String fullPath, String name, int iconId){
		this.FullPath = fullPath;
		this.Name = name;
		this.Path = fullPath.substring(0, fullPath.lastIndexOf("/")+1);
		this.IconId = iconId;
		this.ItemType = ListItemUtil.TYPE_NORMAL;
	}
	
	public ListItem(String fullPath){
		int lastSlash = fullPath.lastIndexOf("/");
		if(lastSlash == -1 || lastSlash+1 > fullPath.length())
		{
			this.Path = "";
			this.Name = "";
			this.IconId = ListItemUtil.ICON_UNKNOWN;
			this.ItemType = ListItemUtil.TYPE_NORMAL;
			return;
		}
		this.FullPath = fullPath;
		this.Path = fullPath.substring(0, lastSlash + 1);
		this.Name = fullPath.substring(lastSlash + 1);
		this.IconId = ListItemUtil.getIconIdByType(this.FullPath);
		this.ItemType = ListItemUtil.TYPE_NORMAL;
		this.FileType = ListItemUtil.getFileType(this.FullPath);
	}
	
	public ListItem(File file){
		this(file.getAbsolutePath());
	}
	
	public ListItem(File file, int type){
		this(file.getAbsolutePath());
		this.ItemType = type;
		if(ItemType == ListItemUtil.TYPE_UPLEVEL)
		{
			this.Name = "..";
			this.IconId = ListItemUtil.ICON_UP_LEVEL;
		}
	}

	public boolean isDirectory(){
		File file = new File(FullPath);
		return file.exists() && file.isDirectory();
	}
	
	
	

}
